import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.omg.CORBA.PUBLIC_MEMBER;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.*;
import java.util.concurrent.atomic.AtomicInteger;

@Slf4j
public class channel {



    @Test
    public void channel(){
        try {
            RandomAccessFile file = new RandomAccessFile("hello.txt", "rw");
            FileChannel channel = file.getChannel();
            //设置了缓冲区
            ByteBuffer allocate = ByteBuffer.allocate(10);
            //开始读取数据
            do{
                int read = channel.read(allocate);
                   log.debug("读到第{}个字节",read);
                   if(read==-1){
                       break;
                   }
                   //切换到allocate的读的模式
                   allocate.flip();
                  while (allocate.hasRemaining()){
                      log.debug(String.valueOf((char)allocate.get()));
                  }
                  //切换回写模式
                  allocate.clear();

            }while (true);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    @Test
    public void cahnnel2(){
        for (int i = 0; i <10 ; i++) {
     //       log.info("hello\n");
        }
    }

    @Test
    public void fileVister(){
        //用于异步计数器

        AtomicInteger atomicInteger = new AtomicInteger();
    }
};
